﻿using System;
using System.Xml;
using InfoJetSoft.Service.Entity;
using InfoJetSoft.Service.Util;
using InfoJetSoft.Service.EscapeRule;

namespace InfoJetSoft.Service.Worker
{

	class FormBuildXMLDocByTemplateWorker
	{
		
		public static void  buildXMLDocByTemplate(Form form)
		{
            //CID 1022 //2011.10.16 //Begin
            XmlDocument xmlDoc = null;
            if (form.Manifest.FormFieldsCacheEnabled)
            {
                xmlDoc = DOMUtil.buildDocPreserveWhitespace(form.Manifest.Template.CabFile.ByteOutput);
            }
            else
            {
                xmlDoc = DOMUtil.buildDoc(form.Manifest.Template.CabFile.ByteOutput);
            }
            //CID 1022 //2011.10.16 //End
            form.XmlDoc = xmlDoc;
			form.XmlNsResolver = new NamespaceResolver(xmlDoc);

			FormConfigContextValue.UpdateWhileOpenTemplate( form );
			
			FormUtil.formatPiHref( form );

			//CID 0451 //2009.11.09 //Begin
			SchemaPSVI.clearXsiNil( form );
			//CID 0451 //2009.11.09 //End

			//CID 0167 //2008.12.15 //Begin
			ImportParameter.ExecuteOnNew( form );
			//CID 0167 //2008.12.15 //End
			//CID 0159 //2008.12.03 //Begin
			form.JetContext.OnXmlDocumentReadyEvent( form );
			//CID 0159 //2008.12.03 //End
			form.JetContext.OnXmlDocumentCompletedEvent( form );
		}
	}
}